<template>
  <el-drawer
    :title="title"
    :visible.sync="visible"
    :size="width"
    :direction="direction"
    @closed="$emit('drawerClose')">
    <template #title>
      <base-text :content="title" class="el-drawer__title"/>
    </template>
    <div class="base-drawer-loading" v-show="isLoading" v-loading="isLoading"/>
    <slot></slot>
  </el-drawer>
</template>

<script>
export default {
  name: 'BaseDrawer',
  props: {
    width: {
      type: [String, Number],
      // document.body.clientWidth <= 1440 ? 700 : '50%'
      default: 700
    },
    direction: {
      type: String,
      default: 'rtl'
    },
    title: {
      type: String,
      default: ''
    },
    drawerId: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      visible: false,
      isLoading: false
    };
  },
  methods: {
    loadingOpen() {
      this.isLoading = true;
    },
    loadingClose() {
      this.isLoading = false;
    }
  },
  watch: {
    drawerId(val) {
      this.visible = !!val;
    }
  }
};
</script>

<style scoped lang="less">
  .base-drawer-loading {
    position: absolute !important;
    top: 55px;
    left: 0;
    right: 0;
    bottom: 0;
  }
</style>
